home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 102_01.zip / WAVY.C < prev    next >
Text File  |  1993-06-03  |  2KB  |  75 lines

  1. /*
  2.     Wavy Lines for the H19/Z19/H89/Z89
  3.     Written by Leor Zolman, 11/81
  4.  
  5.     This program is configured for the H19 terminal, but may be used
  6.     on ANY cursor-addressable terminal by:
  7.  
  8.         a) modifying the first four #define lines to suit your
  9.            particular terminal, and
  10.         b) modifying the cursor addressing sequence (commented)
  11.            in the program to work for your terminal.
  12.  
  13.     For best effect, compile with:
  14.       A>cc1 wavy.c -e2000 -o <cr>
  15. */
  16.  
  17. /* The following four #define statements need customizing for your terminal: */
  18.  
  19. #define INIT    "\33E\33F\33x5"    /* clear screen, enter graphics mode,    */
  20.                 /* and turn off the cursor        */
  21. #define UNINIT    "\33E\33G\33y5"    /* clear screen, exit graphics mode,    */
  22.                 /* and turn cursor back on        */
  23.  
  24. #define SLASH 'x'        /* these are special characters in H19    */
  25. #define BACKSLASH 'y'        /* graphics mode. If you don't have an  */
  26.                 /* H19, make these simply '/' and '\\'    */
  27.  
  28.  
  29. #define MAXL 200        /* maximum number of lines at one time */
  30.  
  31. int direc[MAXL], di;
  32. char column[MAXL], co;
  33. char i;
  34. char nlines;
  35.  
  36. main()
  37. {
  38. top:    puts(UNINIT);
  39.     srand1("How many wavy lines (1-200, q to quit) ? ");
  40.     if (!scanf("%d",&nlines) || nlines < 1 || nlines > MAXL) exit();
  41.     puts(INIT);
  42.  
  43.     di = rand() % 2 * 2 - 1;
  44.  
  45.     for (i=0; i<nlines; i++)    /* initialize lines */
  46.     {
  47.         column[i] = rand() % 80;    /* start out at random spot */
  48.         direc[i] = di;            /* going in same direction */
  49.     }
  50.  
  51.     while (1)
  52.     {
  53.        putch('\n');
  54.        if (kbhit() && getchar()) goto top;    /* if key hit, stop    */
  55.  
  56.        for (i = 0; i < nlines; i++)
  57.        {    
  58.         di = direc[i];
  59.         co = column[i];
  60.  
  61.         putch('\33');        /* position cursor at row 23,     */
  62.         putch('Y');        /*               column co    */
  63.         putch(' '+23);        /*   MODIFY THIS SECTION FOR    */
  64.         putch(' '+co);        /*     NON-H19 TERMINALS!    */
  65.  
  66.         putch ((di < 0) ? SLASH : BACKSLASH);
  67.  
  68.         if ((di > 0) ? (rand() % (79 - co)) : (rand() % (1 + co)))
  69.             column[i] += di;    /* either keep going, or */
  70.         else
  71.             direc[i] = -di;        /* change direction    */
  72.        }
  73.     }
  74. }
  75.